<?php
namespace App\Dao;

use App\Exception\BusinessException;
use App\Model\User;

class UserDao
{
    /**
     * @param $user_id
     * @param bool $throw
     * @return null|SysUserDao
     */
    public function first($user_id, $throw = true)
    {
        $model = User::query()->where('id', $user_id)->first();
        if (empty($model) && $throw) {
            throw new BusinessException('用户不存在');
        }
        return $model;
    }

    /**
     * @param $username
     * @param bool $throw
     * @return mixed
     */
    public function getUserByName($username, $throw = true)
    {
        $model = User::query()->where('username', $username)->first();
        if (empty($model) && $throw) {
            throw new BusinessException('用户不存在');
        }
        return $model;
    }
}